<?php
/**
 * Created by PhpStorm.
 * User: wenjoying@126.com
 * Date: 2018/5/31
 * Time: 10:16
 */

namespace App\Models;

use App\Http\Scopes\EnableScope;
use Exception;

class TaskQuestion extends BaseModel
{
    const COL_ID = 'id';

    /**
     * @var string 表名
     */
    protected $table = 'task_question';

    /**
     * @var string 主键
     */
    protected $primaryKey = 'id';

    /**
     * 填充字段
     * @var array
     */
    protected $fillable = [
        'title',
        'limit_time',
        'type', // '单选','多选'
        'task_id',
        'score',
        'is_enable',
    ];

    /**
     * @desc 隐藏字段
     */
    protected $hidden = [];

    /**
     * @desc 动态增加字段
     */
    protected $appends = [];

    /**
     * @desc 查找字段
     */
    public $columns = [];

    protected static function boot()
    {
        parent::boot();

        static::addGlobalScope(new EnableScope());
    }

    public function task()
    {
        return $this->hasOne(Task::class, 'id', 'task_id');
    }

    public function anwser()
    {
        return $this->hasMany(TaskAnwser::class, 'question_id')->orderByDesc('id');
    }


}